<template>
	<view class="wrap">
		<view class="vips">
			<view class=" tips1">
				<text v-if="!isVip">免广告下载高清原图</text>
				<text v-else>会员到期时间: {{vipExpireTime}}</text>
			</view>
			<view class="info">
				<text v-if="!isVip">未开通（开通会员享受更多权益）</text>
				<text v-else>已开通会员</text>
			</view>
		</view>
		<view class="card">
			<view class="left">
				<view class="top">
					{{topInfo.vipName}}
				</view>
				<view class="bot">
					免广告<br />下载高清原图
				</view>
			</view>
			<view class="right">
				<view class="top">
					{{topInfo.price}}元尊享价
				</view>
				<view class="mid">
					{{topInfo.describe}}
				</view>
				<view @click="topPayment" class="btn">
					立即体验
				</view>
			</view>
		</view>
		<view class="list">
			<view class="titles">
				限量特惠抢购
			</view>
			<scroll-view scroll-x="true" class="data-list ul ">
				<view class="li" @click="clickVip(item,index)" :class="{active:cur==index}"
					v-for="(item,index) in vipList">
					<view class="deco">
						<text>{{item.vipName}}</text>
					</view>
					<view class="price">
						<text class="unit">¥</text>
						<text class="money">{{item.price}}</text>
					</view>
					<view class="old">
						原价{{item.originalPrice}}元
					</view>
				</view>
			</scroll-view>

			<view class="tips">
				{{vipDescribe}}
			</view>
			<view class="record">
				<view class="name">
					他们刚刚购买了会员
				</view>
				<view class="scroll_box">
					<swiper class="swiper" circular="true" vertical="true" display-multiple-items="10"
						:autoplay="autoplay" :interval="interval" :duration="duration">
						<swiper-item v-for="(item,index) in buyList" :key="index">
							<!-- <view class="swiper-item uni-bg-green">{{item}}</view>
							 -->
							<view class="recordList">
								<view class="item">
									<image class="photo" :src="avatar" mode=""></image>
									<view class="name">
										{{item.nickname}}
									</view>
									<view class="desc">
										{{item.time}}购买了会员卡
									</view>
								</view>
							</view>
						</swiper-item>
					</swiper>
				</view>
			</view>

		</view>
		<image src="https://tb.wuyouzhuan888.com/applet-icon/bg.png" class="bg-set" mode=""></image>
		<view class="buy">
			<view class="top">
				<view class="left">
					<view class="unit">
						合计 ¥
					</view>
					<view class="price">
						{{vipPrice}}
					</view>
				</view>
				<view class="btns" @click="payment()">
					立即支付
				</view>
			</view>
		</view>
		<u-popup border-radius="20" v-model="mask2" mode="center">
			<image @click="mask2=false" class="close" src="https://tb.wuyouzhuan888.com/applet-icon/close.png" mode="">
			</image>
			<view class="qq">
				<mask2 @closeDk="closeDk" :content="buyTips" />
			</view>
		</u-popup>

		<u-popup border-radius="20" v-model="mask3" mode="center">
			<image @click="mask3=false" class="close" src="https://tb.wuyouzhuan888.com/applet-icon/close.png" mode="">
			</image>
			<view class="qq">
				<mask3 />
			</view>
		</u-popup>
	</view>
</template>
<script>
	import mask2 from './index2.vue'
	export default {
		components: {
			mask2,
		},
		data() {
			return {
				avatar: '',
				autoplay: true,
				interval: 2000,
				duration: 1000,
				mask2: false,
				cur: 0,
				sample: false,
				// 会员购买列表
				buyList: [],
				// 会员购买成功提示
				buyTips: '',
				// 会员列表
				vipList: [],
				// 会员ID
				vipId: 0,
				// 会员价格
				vipPrice: 0,
				// 会员描述
				vipDescribe: '',
				// 防止抖动
				shake: true,
				// 任务ID
				taskId: 0,
				// 模版ID
				movId: 0,
				// 创作者ID
				creatorId: 0,
				// 账号ID
				accountId: 0,
				collectionId: 0,
				urlId: 0,
				// 资源ID
				resourcesId: 0,
				// 图片数组
				imgList: [],
				// 图集ID
				atlasId: 0,
				// 资源ID
				resourcesId: 0,
				// 测评ID
				assessId: 0,
				callbackId: 0,
				// 会员到期时间
				vipExpireTime: '',
				// 是否是会员
				isVip: false,
				// 置顶会员信息
				topInfo: {
					vipName: '',
					price: 0,
					describe: '',
				},
				// 用户信息授权结果
				authRt: false
			};
		},
		onLoad(options) {
			uni.showLoading({
				title: "加载中...",
			})
			// 体验会员
			this.sample = options.sample ?? false;
			// 任务ID
			this.taskId = options.taskId ?? 0;
			// 模版ID
			this.movId = options.movId ?? 0;
			// 创作者ID
			this.creatorId = options.creatorId ?? 0;
			// 账号ID
			this.accountId = options.accountId ?? 0;
			this.collectionId = options.collectionId ?? 0;
			this.urlId = options.urlId ?? 0;
			// 图集ID
			this.atlasId = options.atlasId ?? 0;
			// 资源ID
			this.resourcesId = options.resourcesId ?? 0;
			// 测评ID
			this.assessId = options.assessId ?? 0;
			this.callbackId = options.callbackId ?? 0;
			// 获取会员信息
			this.getVipInfo()
			if (this.sample) {
				// 获取会员体验列表
				this.getSampleList();
			} else {
				// 获取会员列表
				this.getVipList();
			}

			// 获取会员购买列表
			this.getBuyList();
			// 获取指定会员信息
			this.getTopInfo()
		},
		onShow() {
			this.avatar = uni.getStorageSync('avatar')
			uni.hideLoading()
		},
		// 离开页面事件
		onUnload() {
			this.getOpenerEventChannel().emit('isVip', this.isVip)
		},
		methods: {
			closeDk() {
				this.mask2 = false
			},
			// 点击会员
			clickVip(item, index) {
				this.cur = index
				this.vipDescribe = item.describe
				this.vipPrice = item.price
				this.vipId = item.vipId
			},
			// 获取会员信息
			getVipInfo() {
				this.$u.api.mine.getVipInfo().then(res => {
					if (res.code != 200) {
						this.$u.toast(res.msg)
						return
					}
					this.isVip = res.data.isVip
					this.vipExpireTime = res.data.vipExpireTime
				})
			},
			// 获取会员购买列表
			getBuyList() {
				this.$u.api.vip.getBuyList().then(res => {
					if (res.code != 200) {
						this.$u.toast(res.msg)
						return
					}
					this.buyList = res.data
				})
			},
			// 获取会员列表
			getVipList() {
				this.$u.api.vip.getList().then(res => {
					if (res.code != 200) {
						this.$u.toast(res.msg)
						return
					}
					this.vipList = res.data
					this.vipDescribe = this.vipList[this.cur]['describe']
					this.vipPrice = this.vipList[this.cur]['price']
					this.vipId = this.vipList[this.cur]['vipId']
				})
			},
			// 获取会员列表
			getTopInfo() {
				this.$u.api.vip.getTopInfo().then(res => {
					if (res.code != 200) {
						this.$u.toast(res.msg)
						return
					}
					this.topInfo = res.data
				})
			},
			// 获取体验会员列表
			getSampleList() {
				this.$u.api.vip.getSampleList().then(res => {
					if (res.code != 200) {
						if (res.msg) {
							this.$u.toast(res.msg)
						}
						return
					}
					this.vipList = res.data
					this.vipDescribe = this.vipList[this.cur]['describe']
					this.vipPrice = this.vipList[this.cur]['price']
					this.vipId = this.vipList[this.cur]['vipId']
				})
			},
			// 支付
			async topPayment() {
				if (!this.shake) {
					return
				}
				this.shake = false;
				uni.showLoading({
					title: '发起支付中...'
				})
				await this.getUserInfo().then(res => {
					this.authRt = true
				}).catch(error => {
					this.$u.toast('请授权后购买会员');
				})
				if (!this.authRt) {
					return false;
				}
				let userInfo = uni.getStorageSync('userInfo');
				this.$u.api.dy.createOrder({
					vipId: this.topInfo.vipId,
					nickname: userInfo.nickName,
					avatarUrl: userInfo.avatarUrl,
					taskId: this.taskId,
					movId: this.movId,
					creatorId: this.creatorId,
					accountId: this.accountId,
					atlasId: this.atlasId,
					resourcesId: this.resourcesId,
					collectionId: this.collectionId,
					urlId: this.urlId,
					assessId: this.assessId,
					callbackId:this.callbackId
				}).then(res => {
					if (res.code != 200) {
						this.$u.toast(res.msg)
						return false;
					}
					uni.hideLoading()
					// 调起支付
					this.pay(res.data.order_id, res.data.order_token)
				})
			},
			// 支付
			async payment() {
				if (!this.shake) {
					return
				}
				this.shake = false;
				uni.showLoading({
					title: '发起支付中...'
				})
				await this.getUserInfo().then(res => {
					this.authRt = true
				}).catch(error => {
					this.$u.toast('请授权后购买会员');
					this.authRt = false
				})
				if (!this.authRt) {
					return false;
				}
				let userInfo = uni.getStorageSync('userInfo');
				this.$u.api.dy.createOrder({
					vipId: this.vipId,
					nickname: userInfo.nickName,
					avatarUrl: userInfo.avatarUrl,
					taskId: this.taskId,
					movId: this.movId,
					creatorId: this.creatorId,
					accountId: this.accountId,
					atlasId: this.atlasId,
					resourcesId: this.resourcesId,
					collectionId: this.collectionId,
					urlId: this.urlId,
					assessId: this.assessId,
					callbackId:this.callbackId,
				}).then(res => {
					if (res.code != 200) {
						this.$u.toast(res.msg)
						return false;
					}
					uni.hideLoading()

					// 调起支付
					this.pay(res.data.order_id, res.data.order_token)
				})
			},

			// 调起支付
			pay(order_id, order_token) {
				const that = this;
				// 支付
				tt.pay({
					orderInfo: {
						order_id: order_id,
						order_token: order_token
					},
					service: 5,
					success(res) {
						that.shake = true;
						// 支付成功
						if (res.code == 0) {
							// 校验订单状态
							that.checkOrderStatus(order_id)
						}
					},
					fail(res) {
						that.shake = true;
					}
				});
			},
			// 校验订单状态
			checkOrderStatus(order_id) {
				this.$u.api.dy.checkOrderStatus({
					dyOrderNo: order_id
				}).then(res => {
					if (res.code != 200) {
						this.$utils.msg(res.msg);
						return false;
					}
					this.vipExpireTime = res.data.vipExpireTime
					this.isVip = res.data.isVip
					this.buyTips = res.data.buyTips
					this.mask2 = true
				})
			},
			// 获取用户信息
			getUserInfo() {
				let that = this
				return new Promise((resolve, reject) => {
					if (!uni.getStorageSync('userInfo')) {
						// 获取用户信息
						uni.getUserProfile({
							provider: '',
							success(res) {
								uni.setStorageSync('userInfo', res.userInfo);
								resolve()
							},
							fail() {
								uni.hideLoading()
								that.shake = true;
								reject()
							}
						});
					} else {
						resolve()
					}

				})
			}
		}
	};
</script>
<style scoped lang="scss">
	.scroll-view_H {
		width: 200%;
		display: flex;
		flex-wrap: nowrap;
	}

	.scroll_box {
		padding-bottom: 200rpx;

		.swiper {
			height: 300px;
		}
	}

	/deep/ .u-mode-center-box {
		background: none !important;
		overflow: initial !important;
		margin-top: -80px !important;
	}

	/deep/ .uni-scroll-view,
	/deep/ .uni-scroll-view-content {
		overflow: initial !important;
	}

	.data-list {
		width: 100%;
		white-space: nowrap;
	}


	.close {
		width: 65rpx;
		height: 65rpx;
		display: block;
		position: fixed;
		top: 127rpx;
		right: 41rpx;
		z-index: 999;
		// background: rgba(255,255,255,0.8);
		// margin: 46rpx auto;
	}

	.wrap {
		.buy {
			height: 169rpx;
			position: fixed;
			left: 0;
			right: 0;
			bottom: 0;
			width: 100%;
			background: linear-gradient(to right, rgba(24, 24, 44, 1), rgba(17, 17, 31, 1));

			.top {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding-top: 43rpx;
				margin: 0 32rpx;

				.left {
					display: flex;
					align-items: flex-start;

					.unit {
						margin: 15rpx 10rpx 0 0;
						font-size: 30rpx;
						font-family: PingFang SC-Light, PingFang SC;
						font-weight: 300;
						line-height: 35rpx;
						text-shadow: 0px 2px 0px rgba(30, 19, 100, 0.42);
						background: linear-gradient(180deg, #E1BBFF 0%, #FFFFFF 30%, #F4F2FF 36%, #A479FF 100%);
						-webkit-background-clip: text;
						-webkit-text-fill-color: transparent;
					}

					.price {
						font-size: 64rpx;
						font-family: HYQiHei-40S, HYQiHei;
						font-weight: normal;
						line-height: 75rpx;
						// text-shadow: 0px 2px 0px rgba(30, 19, 100, 0.42);
						background: linear-gradient(180deg, #E1BBFF 0%, #FFFFFF 30%, #F4F2FF 36%, #A479FF 100%);
						-webkit-background-clip: text;
						-webkit-text-fill-color: transparent;
					}
				}

				.btns {
					background: linear-gradient(to right, rgba(70, 89, 255, 1), rgba(161, 129, 255, 1));
					width: 263rpx;
					height: 80rpx;
					border-radius: 70rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 34rpx;
					font-family: PingFang HK-Light, PingFang HK;
					font-weight: 300;
					color: #FFFFFF;
				}
			}
		}

		// margin: 0 32rpx;
		.title {
			font-size: 36rpx;
			font-family: PingFang SC-Light, PingFang SC;
			font-weight: 300;
			color: #FFFFFF;
			line-height: 42rpx;
		}

		.record {
			.name {
				padding: 0 0 14rpx 21rpx;
				font-size: 26rpx;
				font-family: HYQiHei-45S, HYQiHei;
				font-weight: normal;
				color: #7A77EB;
			}

			.recordList {
				margin: 0 18rpx;

				.item {
					margin-bottom: 16rpx;
					font-size: 22rpx;
					font-family: HYQiHei-45S, HYQiHei;
					font-weight: normal;

					display: flex;
					align-items: center;

					.photo {
						width: 47rpx;
						height: 47rpx;
						border-radius: 50%;
					}

					.name {
						min-width: 140rpx;
						padding: 0 14rpx;
						color: #B9B8FF;
					}

					.desc {
						color: #B9B8FF;
					}
				}
			}

		}

		.tips {
			padding: 24rpx 0 32rpx 21rpx;
			font-size: 28rpx;
			font-family: HYQiHei-55S, HYQiHei;
			font-weight: normal;
			line-height: 33rpx;
			// text-shadow: 0px 2px 0px rgba(28, 29, 53, 0.42);
			background: linear-gradient(180deg, #FFE4BB 0%, #FFFFFF 30%, #F4F2FF 42%, #F0DD98 100%);
			-webkit-background-clip: text;
			-webkit-text-fill-color: transparent;
		}

		.list {
			margin: 24rpx 32rpx 200rpx;
			border-radius: 24rpx;
			padding: 32rpx 24rpx;
			background: linear-gradient(to right, rgba(33, 55, 134, 1), rgba(58, 21, 109, 1));

			.ul {
				// display: flex;
				// align-items: center;
				// min-width: 100%;

				.li {
					display: inline-block;
					width: 198rpx;
					height: 192rpx;
					text-align: center;
					border-radius: 12rpx;
					background: url('https://tb.wuyouzhuan888.com/applet-icon/u33.png') no-repeat;
					background-size: cover;
					margin-right: 22rpx;
					border: 1px solid transparent;

					&.active {
						border: 1px solid rgba(175, 161, 255, 1);
					}

					&:last-child {
						margin-right: 0;
					}

					.deco {
						margin: -2rpx auto 5rpx;
						width: 145rpx;
						height: 41rpx;
						// background: linear-gradient(180deg, #7886FF 0%, #4126E5 100%);
						border-radius: 0 0 5px 5px;
						text-align: center;

						text {
							font-size: 24rpx;
							font-family: HYQiHei-55S, HYQiHei;
							font-weight: normal;
							line-height: 28rpx;
							// text-shadow: 0px 2px 0px rgba(30, 19, 100, 0.42);
							background: linear-gradient(180deg, #E1BBFF 0%, #FFFFFF 30%, #F4F2FF 36%, #A479FF 100%);
							-webkit-background-clip: text;
							-webkit-text-fill-color: transparent;
						}
					}

					.price {
						display: flex;
						align-items: flex-end;
						justify-content: center;

						.unit {
							margin-bottom: 10rpx;
							margin-right: 5rpx;
							font-size: 37rpx;
							font-family: PingFang SC-Light, PingFang SC;
							font-weight: 300;
							line-height: 43rpx;
							// text-shadow: 0px 2px 0px rgba(30, 19, 100, 0.42);
							background: linear-gradient(180deg, #FFECBB 0%, #FFFFFF 30%, #F4F2FF 36%, #FFE2AB 100%);
							-webkit-background-clip: text;
							-webkit-text-fill-color: transparent;
						}

						.money {
							font-size: 70rpx;
							font-family: HYQiHei-40S, HYQiHei;
							font-weight: normal;
							line-height: 97rpx;
							// text-shadow: 0px 2px 0px rgba(30, 19, 100, 0.42);
							background: linear-gradient(180deg, #FFE298 0%, #FFFFFF 30%, #F4F2FF 36%, #FFE5A3 100%);
							-webkit-background-clip: text;
							-webkit-text-fill-color: transparent;

						}
					}

					.old {
						text-decoration: line-through rgba(164, 121, 255, 1);
						font-size: 25rpx;
						font-family: PingFang SC-Light, PingFang SC;
						font-weight: 300;
						line-height: 29rpx;
						text-shadow: 0px 2px 0px rgba(30, 19, 100, 0.42);
						background: linear-gradient(180deg, #E1BBFF 0%, #FFFFFF 30%, #F4F2FF 36%, #A479FF 100%);
						-webkit-background-clip: text;
						-webkit-text-fill-color: transparent;
					}
				}
			}

			.titles {
				text-align: center;
				font-size: 32rpx;
				font-family: HYQiHei-55S, HYQiHei;
				font-weight: normal;
				line-height: 38rpx;
				// text-shadow: 0px 2px 0px rgba(28, 29, 53, 0.42);
				background: linear-gradient(180deg, #FFE4BB 0%, #FFFFFF 30%, #F4F2FF 42%, #F0DD98 100%);
				-webkit-background-clip: text;
				-webkit-text-fill-color: transparent;
				margin-bottom: 16rpx;
			}
		}

		.card {
			padding: 20rpx 10rpx 20rpx 24rpx;
			margin: -160rpx 32rpx 25rpx;
			height: 245rpx;
			border-radius: 22rpx;
			// text-shadow: 0px 2px 0px rgba(28, 29, 53, 0.2);
			background: linear-gradient(to right, rgba(24, 50, 141, 1), rgba(73, 21, 144, 1));
			display: flex;

			.right {
				.top {
					padding: 21rpx 0 7rpx 0;
					font-size: 32rpx;
					font-family: HYQiHei-55S, HYQiHei;
					font-weight: normal;
					line-height: 38rpx;
					// text-shadow: 0px 2px 0px rgba(28, 29, 53, 0.2);
					background: linear-gradient(180deg, #FFE4BB 0%, #FFFFFF 30%, #F4F2FF 42%, #F0DD98 100%);
					-webkit-background-clip: text;
					-webkit-text-fill-color: transparent;
				}

				.mid {
					min-height: 40px;
					// margin-bottom: 40rpx;
					font-size: 24rpx;
					font-family: HYQiHei-45S, HYQiHei;
					font-weight: normal;
					color: #A6A4FF;
				}

				.btn {
					border-radius: 70rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					width: 195rpx;
					height: 60rpx;
					font-size: 28rpx;
					font-family: PingFang HK-Light, PingFang HK;
					font-weight: 300;
					color: #FFFFFF;
					background: linear-gradient(to right, rgba(70, 89, 255, 1), rgba(161, 129, 255, 1));
				}
			}

			.left {
				margin-right: 30rpx;
				width: 366rpx;
				height: 204rpx;
				background: url('https://tb.wuyouzhuan888.com/appleticon/u22.png') no-repeat;
				background-size: cover;

				.top {
					padding: 42rpx 0 28rpx 33rpx;
					font-size: 32rpx;
					font-family: HYQiHei-55S, HYQiHei;
					font-weight: normal;
					line-height: 38rpx;
					// text-shadow: 0px 2px 0px rgba(28,29,53,0.42);
					background: linear-gradient(180deg, #FFE4BB 0%, #FFFFFF 30%, #F4F2FF 42%, #F0DD98 100%);
					-webkit-background-clip: text;
					-webkit-text-fill-color: transparent;
				}

				.bot {
					padding-left: 33rpx;
					font-size: 23rpx;
					font-family: HYQiHei-45S, HYQiHei;
					font-weight: normal;
					color: #A6A4FF;
				}
			}
		}

		.vips {
			width: 750rpx;
			height: 540rpx;
			background: url("https://tb.wuyouzhuan888.com/appleticon/u11.png") no-repeat;
			background-size: cover;
			overflow: hidden;

			.tips1 {
				padding: 155rpx 0 32rpx 32rpx;
				font-size: 29rpx;
				font-family: HYQiHei-45S, HYQiHei;
				font-weight: normal;
				color: #E8D6FF;
			}

			.info {
				display: inline-flex;
				margin: 85rpx 0 32rpx 32rpx;
				background: rgba(255, 255, 255, 0.15);
				border-radius: 31rpx;
				padding: 4rpx 6rpx 4rpx 20rpx;
				font-size: 24rpx;
				font-family: PingFang SC-Light, PingFang SC;
				font-weight: 300;
				color: rgba(255, 255, 255, 0.8);

			}
		}

	}
</style>